import 'package:flutter/material.dart';
import "./wiget/Image.dart";

void main() {
  runApp(const MaterialApp(home: HomePage()));
}

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  List<Widget> list = [
    ImageWget('https://www.itying.com/images/flutter/1.png'),
    ImageWget('https://www.itying.com/images/flutter/2.png'),
    ImageWget('https://www.itying.com/images/flutter/3.png'),
    ImageWget('https://www.itying.com/images/flutter/4.png'),
    ImageWget('https://www.itying.com/images/flutter/5.png'),
  ];

  int _currentIndex = 0;
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('你好flutter')),
        body: Stack(
          children: [
            SizedBox(
              height: 200,
              child: PageView.builder(
                itemCount: 1000,
                itemBuilder: (context, index) {
                  return list[index % list.length];
                },
                onPageChanged: (index) {
                  setState(() {
                    _currentIndex = (index % list.length);
                    print(_currentIndex);
                  });
                },
              ),
            ),
            Positioned(
              bottom: 10,
              left: 0,
              right: 0,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: List.generate(
                  list.length,
                  (index) => Container(
                    width: 10,
                    height: 10,
                    margin: const EdgeInsets.all(5),
                    decoration: BoxDecoration(
                      color: _currentIndex == index ? Colors.red : Colors.teal,
                      // borderRadius: BorderRadius.circular(5),
                      shape: BoxShape.circle,
                    ),
                  ),
                ).toList(),
              ),
            )
          ],
        ),
      ),
    );
  }
}
